package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ResourceDto;
import com.zzyl.service.ResourceService;
import com.zzyl.vo.ResourceVo;
import com.zzyl.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "资源(菜单)管理")
@RequestMapping("/resource")
public class ResourceController {
    @Autowired
    ResourceService resourceService;

    /**
     * 资源列表
     * @param resourceDto
     * @return
     */
    @ApiOperation("资源列表")
    @PostMapping("/list")
    public ResponseResult<List<ResourceVo>> list(@RequestBody ResourceDto resourceDto) {
        log.info("资源列表: {}",resourceDto);
        List<ResourceVo> resourceVoList = resourceService.list(resourceDto);
        return ResponseResult.success(resourceVoList);
    }

    /**
     * 菜单树形
     * @return
     */
    @ApiOperation("菜单树形")
    @PostMapping("/tree")
    public ResponseResult<TreeVo> treeList(@RequestBody ResourceDto resourceDto) {
        log.info("菜单树形: {}",resourceDto);
        TreeVo treeVo = resourceService.treeList(resourceDto);
        return ResponseResult.success(treeVo);
    }

    /**
     * 资源添加
     * @param resourceDto
     * @return
     */
    @ApiOperation("资源添加")
    @PutMapping
    public ResponseResult add(@RequestBody ResourceDto resourceDto) {
        log.info("资源添加: {}",resourceDto);
        resourceService.add(resourceDto);
        return ResponseResult.success();
    }
}
